// pages/me/userinfor/userinfor.js
var app = getApp();

Page({

  /**
   * 页面的初始数据
   */
  data: {
    picture: "../../../image/0414couser.png",
    name: "",
    tid:"",
    //user information
    username: "",
    hospitalname: "",
    categoryname: "",
    levelname: "",
    loginname: "",
    hospitalname: "",
    categoryname: "",
    levelname: "",
    price: "",
    vipprice:"",
    groupvipprice:"",
    description:"",

    //科室下拉列表
    suffererArray: null,
    suffererIDArray: null,
    cindex: 0,
  },

  /**
  * 生命周期函数--监听页面加载
  */
  onLoad: function (options) {

    var that = this;

    //接收参数
    that.setData({
      tid: options.TID,
      name: app.globalData.userInfo.nickName,
      picture: app.globalData.userInfo.avatarUrl
    });


    
    var utype = wx.getStorageSync("UserType");
    if (utype == '0') {
      wx.redirectTo({
        url: '/pages/me/myinfor/myinfor'
      })

      return;
    }

    var atkey = wx.getStorageSync("AccessToken");

    wx.showLoading({
      title: '数据加载中...'
    })

    // --------- 发送凭证 ------------------
    wx.request({
      url: app.globalData.getBCBookingItem,
      data: { AccessToken: atkey, TID: that.data.tid },
      header: {
        'content-type': 'application/json'
      },

      success: function (res) {

        that.setData({
          username: res.data.datum.NAME,
          hospitalname: res.data.datum.HOSPITALNAME,
          categoryname: res.data.datum.CATEGORYNAME, 
          levelname: res.data.datum.LEVELNAME,
          groupprice: res.data.datum.GROUPPRICE,
          hospitalname: res.data.datum.HOSPITALNAME,
          categoryname: res.data.datum.CATEGORYNAME,
          levelname: res.data.datum.LEVELNAME,
          price: res.data.datum.PRICE,
          vipprice: res.data.datum.VIPPRICE,
          groupvipprice: res.data.datum.GROUPVIPPRICE,
          description: res.data.datum.DESCRIPTION
        });


        wx.hideLoading(); 

      },
      fail: function () {
        util.showRejectToast('数据加载失败！');
      }
    })



  },

  bindSuffererPickerChange: function (e) {
    this.setData({
      cindex: e.detail.value
    });
  },

  loadSufferer: function () {

    var that = this;
    var atkey = wx.getStorageSync("AccessToken");
    var hid = this.data.hospitalIDArray[this.data.index];
    // --------- 发送凭证 ------------------
    wx.request({
      url: app.globalData.getCategoryList,
      data: {
        AccessToken: atkey,
        hospitalID: hid
      },
      header: {
        'content-type': 'application/json'
      },

      success: function (res) {

        if (!res.data.result) {
          util.showRejectToast(res.data.reason);
          return;
        }

        that.setData({
          categoryArray: res.data.datum.values,
          categoryIDArray: res.data.datum.ids
        });

      },
      fail: function () {
        util.showRejectToast('加载科室信息失败！');
      }

    })


  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function (options) {
    app.userlogin();
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})